<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{lib/css/main.css}">
    <link rel="stylesheet" th:href="@{/lib/css/public.css}">

    <script th:src="@{/lib/js/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>


    <style>

        .layui-form input{
            width:215px;
        }
        .body{
            margin-left: 200px;
            height:800px;
        }
        #image2{
            wdith:100px;
            height: 100px;
        }
        .layui-upload-list{
            margin-left: 120px;

        }
        .layui-upload-img{
            wdith:100px;
            height: 100px;
        }
        body{
            background: url("images/background/page_bg.JPG");
            background-size: 100%;

        }
    </style>

    <script>
        layui.use('element', function(){
            var element = layui.element;

            //…
        });
        //上传照片
        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: '/upload/'
                ,accept:'images'
                ,size:50000
                ,before: function(obj){

                    obj.preview(function(index, file, result){

                        $('#demo1').attr('src', result);
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                    var fileupload = $(".stuImage");
                    fileupload.attr("value",res.data.src);
                    console.log(fileupload.attr("value"));
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });


        });

    </script>
</head>
<body>
<!--<div th:replace="menu/left :: leftbar" ></div>-->
<!--<div th:replace="menu/top :: topbar"></div>-->
<div class="body">
    <h2 class="tablename">发布套餐</h2>
    <hr class="layui-bg-gray">
    <div class="form">
        <br>
        <form id="form1" class="layui-form" enctype="multipart/form-data">

            <div class="layui-form-item">



                <label class="layui-form-label">套餐拓展:</label>
                <div class="layui-input-inline">
                    <input id="name" type="text" name="petName"  placeholder="例如：优质泰迪套餐..." autocomplete="off" class="layui-input stuName">
                </div>

            </div>
            <!--************这里是上传图片的代码***************-->
            <!--************这里添加的隐藏的输入框，用来传递images的参数***************-->
            <!--<input type="hidden" name="stuImage" class="stuImage" value="/images/2019-08-02/5705f0d1-4627-4f76-a630-9193866655fb.jpg">-->
            <!--<div class="layui-form-item">-->
                <!--<label class="layui-form-label ">宠物照片:</label>-->
                <!--<div class="layui-upload">-->
                    <!--<input id="imageFile"  name="imgUrl" type="file" style="margin-left:40px;display:inline-block;height:34px;"/>-->
                    <!--&lt;!&ndash;<div class="layui-upload-list">&ndash;&gt;-->
                        <!--&lt;!&ndash;<img class="layui-upload-img" id="demo1" src="/images/2019-08-02/5705f0d1-4627-4f76-a630-9193866655fb.jpg">&ndash;&gt;-->
                        <!--&lt;!&ndash;<p id="demoText"></p>&ndash;&gt;-->
                    <!--&lt;!&ndash;</div>&ndash;&gt;-->
                <!--</div>-->
            <!--</div>-->
            <!--&lt;!&ndash;************上面里是上传图片的代码***************&ndash;&gt;-->


            <!--<div class="layui-form-item">-->
                <!--<label class="layui-form-label">宠物种类:</label>-->
                <!--<div class="layui-input-block">-->
                    <!--<input id="zhonglei" type="text" name="petZhonglei" required class="layui-input stuAge" placeholder="例如：猫,狗,兔子,鱼,爬行动物..."/>-->


                <!--</div>-->
            <!--</div>-->





                <!--<div class="layui-inline">-->
                    <!--<label class="layui-form-label">宠物类型:</label>-->
                    <!--<div class="layui-input-inline">-->
                        <!--<input id="leixing" type="text" name="petType"  placeholder="狗：萨摩耶,泰迪..." required class="layui-input stuAge">-->
                    <!--</div>-->
                <!--</div>-->



            <div class="layui-form-item">
                <div class="layui-input-block">
                    &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="addorder()">添加</button>
                    &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                    <button type="reset" class="layui-btn layui-btn-radius  layui-btn-danger">重置</button>
                </div>
            </div>

        </form>



    </div>

</div>

<script>

    // //添加宠物信息
    // function petadd(){
    //   var name =  $("#name").val()
    //   var zhonglei =  $("#zhonglei").val()
    //   var leixing =  $("#leixing").val()
    //     var file = $("#imageFile")[0].files[0];
    //
    //     var formData = new FormData();
    //
    //     if(name == '' || name == null){
    //         alert("请填写完整字段")
    //         return false
    //     }else if(zhonglei == '' || zhonglei ==null){
    //         alert("请填写完整字段")
    //         return false
    //     }else if(leixing == '' || leixing== null){
    //         alert("请填写完整字段")
    //         return false
    //     }
    //     if(file != ''){
    //         formData.append("file", file);
    //     }
    //     formData.append("petName", name);
    //     formData.append("petZhonglei", zhonglei);
    //     formData.append("petType", leixing);
    //
    //
    //     $.ajax({
    //         url:"/petadd",
    //         type:"POST",
    //         data:formData,
    //         cache: false, //上传文件不需要缓存
    //         contentType: false, //不设置内容类型
    //         processData: false, //不处理数据
    //         success:function (data){
    //             alert("上传成功！请勿从重新上传")
    //         },
    //         error:function () {
    //             alert("error")
    //         }
    //     })
    //
    //
    //
    //
    // }

function addorder(){
    var val = $("#name").val()
    if(val == null || val == ''){
        alert("请输入信息在添加！")
        return false;
    }
   $.ajax({
       url:"/rraddorder",
       data:{"tuozahan":val},
       type:"POST",
       success:function(data){
           if(data == 1){
               alert('添加成功！')
               $("#name").val('')
           }
       },
       error:function(){
           alert('系统内部出现问题，请联系技术人员！')
       }
   })
}








</script>


</body>
</html>